home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / TABCNTRL.PAK / INIT.C < prev    next >
C/C++ Source or Header  |  1997-05-06  |  6KB  |  145 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   init.c
  9. //
  10. //  PURPOSE:   Performs application and instance specific initialization.
  11. //
  12. //  FUNCTIONS:
  13. //    InitApplication() - Initializes window data and registers window.
  14. //
  15. //  COMMENTS:
  16. //
  17.  
  18. #include <windows.h>            // required for all Windows applications
  19. #include "globals.h"            // prototypes specific to this application
  20. #include "resource.h"
  21.  
  22. HINSTANCE hInst;                // current instance
  23.  
  24. char szAppName[9];              // The name of this application
  25. char szChildName[9];            // Class Name for the child window
  26. char szTitle[40];               // The title bar text
  27.  
  28. //
  29. //  FUNCTION: InitApplication(HINSTANCE, int)
  30. //
  31. //  PURPOSE: Initializes window data and registers window class.
  32. //
  33. //  PARAMETERS:
  34. //    hInstance - The handle to the instance of this application that
  35. //                is currently being executed.
  36. //    nCmdShow  - Specifies how the main window is to be displayed.
  37. //
  38. //  RETURN VALUE:
  39. //    TRUE  - Success
  40. //    FALSE - Initialization failed
  41. //
  42. //  COMMENTS:
  43. //
  44. //    This function is called at application initialization time.  It
  45. //    performs initialization tasks for the current application instance.
  46. //    Unlike Win16, in Win32, each instance of an application must register
  47. //    window classes.
  48. //
  49. //    In this function, we initialize a window class by filling out a data
  50. //    structure of type WNDCLASS and calling the Windows RegisterClass()
  51. //    function.  Then we create the main window and show it.
  52. //
  53. //
  54.  
  55. BOOL InitApplication(HINSTANCE hInstance, int nCmdShow)
  56. {
  57.     WNDCLASSEX wc;
  58.     HWND       hwnd; // Main window handle.
  59.  
  60.     // Load the application name and description strings.
  61.  
  62.     LoadString(hInstance, IDS_APPNAME, szAppName, sizeof(szAppName));
  63.     LoadString(hInstance, IDS_CHILDNAME, szChildName, sizeof(szChildName));
  64.     LoadString(hInstance, IDS_DESCRIPTION, szTitle, sizeof(szTitle));
  65.  
  66.     // Save the instance handle in static variable, which will be used in
  67.     // many subsequence calls from this application to Windows.
  68.  
  69.     hInst = hInstance; // Store instance handle in our global variable
  70.  
  71.     // Fill in window class structure with parameters that describe the
  72.     // main window.
  73.  
  74.     wc.cbSize        = sizeof(WNDCLASSEX);
  75.     wc.style         = CS_HREDRAW | CS_VREDRAW; // Class style(s).
  76.     wc.lpfnWndProc   = (WNDPROC)WndProc;        // Window Procedure
  77.     wc.cbClsExtra    = 0;                       // No per-class extra data.
  78.     wc.cbWndExtra    = 0;                       // No per-window extra data.
  79.     wc.hInstance     = hInstance;               // Owner of this class
  80.     wc.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPICON)); // Icon name from .RC
  81.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW); // Cursor
  82.     wc.hbrBackground = GetStockObject(LTGRAY_BRUSH); // Gray Bkgnd color
  83.     wc.lpszMenuName  = szAppName;               // Menu name from .RC
  84.     wc.lpszClassName = szAppName;               // Name to register as
  85.     wc.hIconSm       = LoadImage(hInstance,        // Load small icon image
  86.                                  MAKEINTRESOURCE(IDI_APPICON),
  87.                                  IMAGE_ICON,
  88.                                  16, 16,
  89.                                  0);
  90.  
  91.     // Register the window class and return FALSE if unsuccesful.
  92.  
  93.     if (!RegisterClassEx(&wc))
  94.     {
  95.         //Assume we are running on NT where RegisterClassEx() is
  96.         //not implemented, so let's try calling RegisterClass().
  97.  
  98.         if (!RegisterClass((LPWNDCLASS)&wc.style))
  99.             return FALSE;
  100.     }
  101.  
  102.     // Fill in window class structure with parameters that describe the
  103.     // child window.
  104.  
  105.     wc.lpfnWndProc   = (WNDPROC)ChildWndProc;   // Child Window Procedure
  106.     wc.hIcon         = NULL;                    // No class icon
  107.     wc.lpszMenuName  = NULL;                    // Child ID
  108.     wc.lpszClassName = szChildName;             // Name of child window class
  109.     wc.hIconSm       = NULL;                    // No class icon
  110.  
  111.     // Register the child class and return FALSE if unsuccesful.
  112.  
  113.     if (!RegisterClassEx(&wc))
  114.     {
  115.         //Assume we are running on NT where RegisterClassEx() is
  116.         //not implemented, so let's try calling RegisterClass().
  117.  
  118.         if (!RegisterClass((LPWNDCLASS)&wc.style))
  119.             return FALSE;
  120.     }
  121.  
  122.     // Create a main window for this application instance.
  123.     hwnd = CreateWindow(szAppName,           // See RegisterClass() call
  124.                         szTitle,             // Text for window title bar
  125.                         WS_OVERLAPPEDWINDOW  // Window style
  126.                          & ~WS_THICKFRAME,
  127.                         CW_USEDEFAULT, 0,    // Use default positioning
  128.                         600,                 // Width
  129.                         400,                 // Height
  130.                         NULL,                // Overlapped has no parent
  131.                         NULL,                // Use the window class menu
  132.                         hInstance,           // This instance owns this window
  133.                         NULL);               // Don't need data in WM_CREATE
  134.  
  135.     // If window could not be created, return "failure"
  136.     if (!hwnd)
  137.         return FALSE;
  138.  
  139.     // Make the window visible; update its client area; and return "success"
  140.     ShowWindow(hwnd, nCmdShow);  // Show the window
  141.     UpdateWindow(hwnd);          // Sends WM_PAINT message
  142.  
  143.     return TRUE;                 // We succeeded...
  144. }
  145.